// 头部线条效果---lang   ajax 调用
var txt = '',
	j_timer = null;
$(function(){
	j_timer = setInterval('shi_Time()', 60000);
	shi_Time();
	$("nav ul li").mouseenter(function () {
		$(this).find("i").animate({"width": $(this).width()},200);
	}).mouseleave(function () {
		$(this).find("i").stop().animate({'width': 0}, 100);
	});
})
// 导航
$(window).scroll(function(event) {
		var scroll_h = $(window).scrollTop();
		//header滚动效果
		if(scroll_h == 0) {
			$("header").removeClass("slide-header");
			$("header").fadeIn(300);
			$('.nav-r ul li a img').attr('src',Imgurl_2)
		}
		if(scroll_h < 90 && scroll_h != 0) {
			$("header").hide();
			$('.nav-r ul li a img').attr('src',Imgurl_2)
		}
		if(scroll_h > 90) {
			$("header").addClass("slide-header");
			$('.nav-r ul li a img').attr('src',Imgurl_1)
			$("header").fadeIn(300);
		}
	})
//滚动条停止后
$(window).on('scrollstop', function(e) {
	changeColor();
});
// 导航
$(function() {
	/* ------ banner ------ */
	banner();
	/* ------ tab ------- */
	$(".left_tab a").click(function(){
        $(".left_tab a").eq($(this).index()).addClass("active").siblings().removeClass('active');
		$(".j_con_tab").hide().eq($(this).index()).show();
    });
	/* 去除火狐下A标签的虚框 */
	var oA = document.getElementsByTagName('a');
	for(var i = 0;i<oA.length;i++){
		oA[i].onfocus = function(){
			this.blur();
		}
	}
    /* 复制链接  */
	var clipboard = new Clipboard('#cp-btn');
	clipboard.on('success', function(e) {
		layer.tips('复制成功','#cp-btn',{time:1000}) 
		e.clearSelection(); 
	});
	clipboard.on('error', function(e) { 
		layer.tips('复制失败，请手动复制','#cp-btn',{time:1000}) 
	});
})
// 2017-05-5-05 轮播
function banner() {
	var index = 0;
	var nextIndex;
	var timmer = null;
	var len = $(".banner ul li").length;

	function autoPlay() {
		timmer = setInterval(slider, 7000)
	}

	function slider() {
		if(index == len) {
			index = 0
		}
		nextIndex = index + 1;
		if(index == len - 1) {
			nextIndex = 0;
		}
		$(".banner ul li").eq(index).fadeOut(1000).removeClass("move");
		$(".banner ul li").eq(nextIndex).fadeIn(1000).addClass("move");
		index++;
	}
	$(".banner").hover(function() {
		$(".banner span").fadeIn(300);
	}, function() {
		$(".banner span").fadeOut(300);
	});
	$(".banner .prev").click(function() {
		if(index == 0) {
			nextIndex = len - 1;
		}
		if(index == -1) {
			index = len - 1;
		}
		nextIndex = index - 1;
		$(".banner ul li").eq(index).fadeOut(1000).removeClass("move");
		$(".banner ul li").eq(nextIndex).fadeIn(1000).addClass("move");
		index--;
		clearInterval(timmer);
		autoPlay();
	})
	$(".banner .next").click(function() {
		slider();
		clearInterval(timmer);
		autoPlay();
	})
	autoPlay();
};
// 2017-05-12  数字滚动
$(function(){
	$.fn.countTo = function(a) {
	    a = a || {};
	    return $(this).each(function() {
	        var c = $.extend({},
	        $.fn.countTo.defaults, {
	            from: $(this).data("from"),
	            to: $(this).data("to"),
	            speed: $(this).data("speed"),
	            refreshInterval: $(this).data("refresh-interval"),
	            decimals: $(this).data("decimals")
	        },
	        a);
	        var h = Math.ceil(c.speed / c.refreshInterval),
	        i = (c.to - c.from) / h;
	        var j = this,
	        f = $(this),
	        e = 0,
	        g = c.from,
	        d = f.data("countTo") || {};
	        f.data("countTo", d);
	        if (d.interval) {
	            clearInterval(d.interval)
	        }
	        d.interval = setInterval(k, c.refreshInterval);
	        b(g);
	        function k() {
	            g += i;
	            e++;
	            b(g);
	            if (typeof(c.onUpdate) == "function") {
	                c.onUpdate.call(j, g)
	            }
	            if (e >= h) {
	                f.removeData("countTo");
	                clearInterval(d.interval);
	                g = c.to;
	                if (typeof(c.onComplete) == "function") {
	                    c.onComplete.call(j, g)
	                }
	            }
	        }
	        function b(m) {
	            var l = c.formatter.call(j, m, c);
	            f.html(l)
	        }
	    })
	};
	$.fn.countTo.defaults = {
	    from: 0,
	    to: 0,
	    speed: 1000,
	    refreshInterval: 100,
	    decimals: 0,
	    formatter: formatter,
	    onUpdate: null,
	    onComplete: null
	};
	function formatter(b, a) {
	    return b.toFixed(2)
	}
	$("#count-number").data("countToOptions", {
	    formatter: function(b, a) {
	        return b.toFixed(0).replace(/\B(?=(?:\d{3})+(?!\d))/g, ",")
	    }
	});
	$(".timer").each(count);
	function count(a) {
	    var b = $(this);
	    a = $.extend({},
	    a || {},
	    b.data("countToOptions") || {});
	    b.countTo(a)
	};
})
// 2017-05-26 数字滚动ajax 封装
function shi_Time(){
	// clearInterval(j_timer)
	$.ajax({
		type : 'post',
		data : '',
		url  : url_one,
		dataType: "json",
		headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
		success:function(res){
			if (res){
				for (var i = 0; i < res.length; i++){
					txt += '<li>';
					txt += '<span>';
					if (res[i].photo){
						txt += '<img src=' + res[i].photo + ' alt="">';
					} else{
						txt += '<img src="'+j_header+'" alt="">';
					}
					if (res[i].isvip == '1'){
						txt += '<img class="j_vip" src="'+j_header_v+'" alt="">';
					}
					txt += '</span>';
					txt += '<div class="j_first_child">';
					txt += '<p class="j_name">' + res[i].username + '</p>';
					txt += '<p class="j_name_vip">';
					if (res[i].isanalyst == '1'){
						txt += '<img class="j_vip" src="'+j_greatmaster+'" alt="">';
					} else if (res[i].isanalyst == '2'){
						txt += '<img class="j_vip" src="" alt="">';
					}
					txt += '</p>';
					txt += '</div>';
					txt += '<div>';
					txt += '<p class="j_name">' + res[i].typename + '</p>';
					txt += '<p class="j_name_vip">交易品种</p>';
					txt += '</div>';
					txt += '<div>';
					txt += '<p class="j_name">' + res[i].begin_point.toString().substr(0, (res[i].begin_point.toString().length - 2)) + '<s>' + res[i].begin_point.toString().substr(res[i].begin_point.toString().length - 2) + '</s></p>';
					txt += '<p class="j_name_vip">开仓价</p>';
					txt += '</div>';
					txt += '<div>';
					txt += '<p class="j_name">' + res[i].end_point.toString().substr(0, (res[i].end_point.toString().length - 2)) + '<s>' + res[i].end_point.toString().substr(res[i].end_point.toString().length - 2) + '</s></p>';
					txt += '<p class="j_name_vip">平仓价</p>';
					txt += '</div>';
					txt += '<div class="j_first_child j_last_child">';
					txt += '<p class="j_name">' + (res[i].final_point+5) + '</p>';
					txt += '<p class="j_name_vip">获利</p>';
					txt += '</div>';
					txt += '</li>';
				}
				$('#j_Master_box').html(txt);
				var j_Master = $("#j_Master_box");
				var j_Master_length = j_Master.children().length;
				if (j_Master_length > 5) {
					setInterval(function () {
						var j_All = j_Master.children();
						var j_last = $(j_All[j_All.length - 1]);
						var j_first = $(j_All[0]);
						j_first.slideDown("slow");
						j_first.addClass('active');
						j_first.next().removeClass('active');
						setTimeout(function () {
							j_last.remove();
							j_last.css({ display: 'none' });
							j_last.prependTo(j_Master);
						}, 1000);
					}, 3000);
				}
			}
		}
	})
}

